(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.reportView.defaultViewController', defaultViewController);
	defaultViewController.$inject = [ '$scope', 'Constants', 'layoutConfig', 'validatorConfig', 'gridService', 'authService', 'reportViewService', 'modalService', 'commonService' ];
	function defaultViewController($scope, Constants, layoutConfig, validatorConfig, gridService, authService, reportViewService, modalService, commonService) {
		var ctrl = this, reportViewInfo = $scope.$stateParams.params;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.companyRpt = reportViewInfo || {};

		ctrl.init = function() {
			// build dynaparm page by report template
			// reportAsyn, if asyn or sync
		};
		
		ctrl.report = function() {
			var param = {};
			param.srcTxnRef = ctrl.companyRpt.companyRptId;
			param.isTemporary = "N";
			commonService.openDocument(param, 'do/cda/reportView/download');
		};
		
		ctrl.download = function() {
			var param = {};
			param.srcTxnRef = ctrl.companyRpt.companyRptId;
			param.isTemporary = "N";
			commonService.download(param, 'do/cda/reportView/download');
		};
		
		
		ctrl.asynReport = function() {
			authService.asynReport(ctrl.companyRpt).then(asynReportSuccessful, asynReportFailed);
		};
		
		ctrl.asynReportList = function() {
			var params = {};
			params.reportCode = ctrl.companyRpt.reportCode;
			modalService.openCustomDialogs({
			   'title': 'Request Info',
			   'dialogsModule' : 'cda.reportreq',
			   'params':params,
			   'btnCallback' : {
					'ok' : function(reportreq) {
					}
				}		
			});
		};
		
		function asynReportSuccessful(response) {
			var params = {};
			params.reportCode = ctrl.companyRpt.reportCode;
			params.requestId = response.data.requestId;
			modalService.openCustomDialogs({
			   'title': 'Request Info',
			   'dialogsModule' : 'cda.reportreq',
			   'params':params,
			   'btnCallback' : {
					'ok' : function(reportreq) {						
					}
				}		
			});
		}

		function asynReportFailed(response) {
			modalService.openErrorDialogs({
				'messages' : response.error
			});
		}
		
	}
})(angular);